/**
 * Program to test your camera. It also makes a video without
 * sound, by the name test_reccord.avi in the working directory.
 */

#include <highgui.h>
#include <cv.h>
#include <assert.h>
#include <iostream>

using namespace std;

int main(int argc, char *argv[])
{
	string wname("Recording...");
	string rname("test_record.avi");
	cvNamedWindow(wname.c_str(), CV_WINDOW_AUTOSIZE);
	CvCapture *camcap = cvCreateCameraCapture(0);
	assert(camcap);
	IplImage *frame;
	double fps = 30; // get fps for the camera
	CvSize size = cvSize((int) cvGetCaptureProperty(camcap, CV_CAP_PROP_FRAME_WIDTH),
			(int)cvGetCaptureProperty(camcap, CV_CAP_PROP_FRAME_HEIGHT));
	CvVideoWriter *writer = cvCreateVideoWriter(rname.c_str(), CV_FOURCC('M', 'J', 'P', 'G'), fps, size);

	while(true){
		frame = cvQueryFrame(camcap);
		assert(frame);
		cvShowImage(wname.c_str(), frame);
		cvWriteFrame(writer, frame);
		char c = cvWaitKey(33.3);
		if(c == 'q') break;
	}

	cvReleaseVideoWriter(&writer);
	cvReleaseImage(&frame);
	cvReleaseCapture(&camcap);
	cvDestroyWindow(wname.c_str());
}

// LaFolle
